﻿namespace _5._9._03.MathFunctionsPerformance
{
    using System;
    using System.Diagnostics;

    class MathFunctionsPerformanceMain
    {
        public const int ONE_MILLION = 1000000;

        static void Float()
        {
            Stopwatch sw = new Stopwatch();

            Console.WriteLine("--- float ---");
            
            sw.Start();
            for (int i = 0; i < ONE_MILLION; i++)
            {
                Math.Sqrt(34.0f);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - square root");

            sw.Reset();
            sw.Start();
            for (int i = 0; i < ONE_MILLION; i++)
            {
                Math.Log(34.0f);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - logarithm");

            sw.Reset();
            sw.Start();
            for (int i = 0; i < ONE_MILLION; i++)
            {
                Math.Sin(34.0f);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - sinus");
        }

        static void Double()
        {
            Stopwatch sw = new Stopwatch();

            Console.WriteLine("--- double ---");


            sw.Start();
            for (int i = 0; i < ONE_MILLION; i++)
            {
                Math.Sqrt(34.0);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - square root");

            sw.Reset();
            sw.Start();
            for (int i = 0; i < ONE_MILLION; i++)
            {
                Math.Log(34.0);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - logarithm");

            sw.Reset();
            sw.Start();
            for (int i = 0; i < ONE_MILLION; i++)
            {
                Math.Sin(34.0);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - sinus");
        }

        static void Decimal()
        {
            Stopwatch sw = new Stopwatch();

            Console.WriteLine("--- decimal ---");


            sw.Start();
            for (int i = 0; i < ONE_MILLION; i++)
            {
                Math.Sqrt((double)34.0m);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - square root");

            sw.Reset();
            sw.Start();
            for (int i = 0; i < ONE_MILLION; i++)
            {
                Math.Log((double)34.0m);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - logarithm");

            sw.Reset();
            sw.Start();
            for (int i = 0; i < ONE_MILLION; i++)
            {
                Math.Sin((double)34.0m);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - sinus");
        }

        static void Main()
        {
            Float();

            Double();

            Decimal();
        }
    }
}